package com.chuangjiangx;


/**
 * @author cj-ch
 * @date 2018/10/26 下午2:22
 */
public class Cal1 {
    public static void main(String[] args) {
        System.out.println(g("hhhhhhhhhhhhhh","hhhhhhhhhhhhhhhhkghgvhhhhhhhhhhhhheogvrhgvoivhnrovirvnrionir"));
    }

    private static final String g(String s1,String s2){
        String r="";
        int len1 = s1.length();
        int len2 = s2.length();
        String sub,str;
        if(len1 == len2){
            sub = s1;
            str = s2;
        }else{
            sub = len1 < len2 ? s1 : s2;
            str = len1 < len2 ? s2 : s1;
        }
        if(str.contains(sub)){
            return sub;
        }
        for(int i=0,n = sub.length();i<n;i++){
            for(int j=(i+1); j<n; j++){
                String substring = sub.substring(i, j);
                if(str.contains(substring)){
                    if(substring.length() > r.length()){
                        r = substring;
                    }
                }
            }
        }
        return r;
    }
}
